package gamble.money.command;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import gamble.money.dao.MoneyDoaImpl;
import gamble.money.vo.MoneyDetailVo;
import gamble.money.vo.PageVO;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MoneyListController {
	
	private MoneyDoaImpl dao;
	PageVO vo;
	List<MoneyDetailVo> list;
	int currentPage=1; //현재 페이지번호
    int blockCount=5; //한페이지당 보여줄 레코드 수
    int blockPage=5; //한 블록당 보여줄 페이지 수
    
    
	public void setDao(MoneyDoaImpl dao) {
		this.dao = dao;
	}
	@RequestMapping("/chargelist.do")
	public ModelAndView chargelist(HttpServletRequest request, PageVO pv){
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		System.out.println("chargelist id : "+id);
		
		int str=pv.getCurrentPage();
		currentPage=(str==0  ? 1 :str);
		int totalCount=dao.getCount(id);
		
		if(totalCount>=0){
		 	 pv=new PageVO(currentPage,totalCount,blockCount,blockPage,id);
		 	 list = dao.getList(pv);
		}
		
		
		ModelAndView mv=new ModelAndView();
		mv.addObject("currentPage",currentPage);
		mv.addObject("list",list);
		mv.addObject("pv",pv);
		mv.setViewName("/money/chargelist");
		return mv;
	}
	
}
